package com.yxh.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yxh.R;
import com.yxh.dto.LessonDto;

@SuppressLint("InflateParams") public class ClassSelectAdapter extends BaseAdapter {

	private List<LessonDto> list;
	private LayoutInflater inflater;

	public ClassSelectAdapter(Context context, List<LessonDto> list) {
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public LessonDto getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.activity_class_select_list_item, null);
			holder = new ViewHolder();
			holder.tv = (TextView) convertView
					.findViewById(R.id.tv);
			holder.img = (ImageView)convertView.findViewById(R.id.img);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		LessonDto lDto = list.get(position);
		if (!TextUtils.isEmpty(lDto.name))
			holder.tv.setText(lDto.name);
		if ("0".equals(lDto.isSelected))
			holder.img.setEnabled(false);
		else
			holder.img.setEnabled(true);
		return convertView;
	}

	static class ViewHolder {
		TextView tv;
		ImageView img;
	
	}

}
